package com.szholly.plug.form.core;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.handler.AbstractHandlerMapping;

/**
 * 自定义Spring MVC路由对象
 */
@Component
public class CustomHandlerMapping extends AbstractHandlerMapping {

	@Autowired
	private FormHandler formController;
	
	@Override
	protected Object getHandlerInternal(HttpServletRequest request)
			throws Exception {
		String lookupPath = getUrlPathHelper().getLookupPathForRequest(request);
		if(lookupPath.startsWith("/form/")){
			HandlerExecutionChain chain = new HandlerExecutionChain(formController);
			return chain;
		}else{
			return null;
		}
	}
}